package com.ming.ThreadDemo;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Auther: tangC
 * @Date: 2020/7/8 16:08
 * @Description:
 */
public class MyThread implements Runnable {

    
    @Override
    public void run() {
        String threadName = Thread.currentThread().getName();
        if (threadName.contains("A")){
            runInner1();
        }
        if (threadName.contains("B")){
            runInner2();
        }
        if (threadName.contains("C")){
            runInner3();
        }
    }
    private void runInner1(){
        try {
            System.out.println(Thread.currentThread().getName()+"-----startTime:"+new SimpleDateFormat("hh;mm;ss").format(new Date()));
            Thread.sleep(10000);
            System.out.println(Thread.currentThread().getName()+"--------endTime:"+new SimpleDateFormat("hh;mm;ss").format(new Date()));
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    private void runInner2(){
        System.out.println(Thread.currentThread().getName()+"进入");
        synchronized (this){
            try {
                System.out.println(Thread.currentThread().getName()+"-----startTime:"+new SimpleDateFormat("hh;mm;ss").format(new Date()));
                Thread.sleep(10000);
                System.out.println(Thread.currentThread().getName()+"-----endTime:"+new SimpleDateFormat("hh;mm;ss").format(new Date()));
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    private synchronized void runInner3(){
        try {
            System.out.println(Thread.currentThread().getName()+"-----startTime:"+new SimpleDateFormat("hh;mm;ss").format(new Date()));
            Thread.sleep(10000);
            System.out.println(Thread.currentThread().getName()+"-------endTime:"+new SimpleDateFormat("hh;mm;ss").format(new Date()));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
